package charts.series.bars ;

import charts.series.bars.Base;
import flash.display.Sprite;
import flash.geom.Point;


class Stack extends Base {
		var total: Float;
	
	public function new ( index: Int, style:Dynamic, group: Float ) {
		
		// we are not passed a string value, the value
		// is set by the parent collection later
		this.total =  style.total;
		super(index, style, style.color, style.tip, style.alpha, group);
	}

		override function replace_magic_values( t:String ): String {
		
		t = super.replace_magic_values(t);
		t = StringTools.replace(t,'#total#', NumberUtils.formatNumber( this.total ));
		
		return t;
	}
	
	public function replace_x_axis_label( t:String ): Void {
		
		this.tooltip = StringTools.replace(this.tooltip,'#x_label#', t );
	}
			
	//
	// BUG: we assume that all are positive numbers:
	//
	public override function resize ( sc:ScreenCoordsBase ):Void {
		this.graphics.clear();
		
		var sc2:ScreenCoords = cast(sc,ScreenCoords);
		
		var tmp:Dynamic = sc2.get_bar_coords( this.index, this.group );
		
		// move the Sprite Into position:
		this.x = tmp.x;
		this.y = sc.get_y_from_val( this.top, this.right_axis );
		
		var height: Float = sc.get_y_from_val( this.bottom, this.right_axis) - this.y;

		this.graphics.beginFill( this.color, 1 );
		this.graphics.drawRect( 0, 0, tmp.width, height );
		this.graphics.endFill();
		
		this.tip_pos = new flash.geom.Point( this.x + (tmp.width / 2), this.y );
	}
}
